import { Component, Input } from '@angular/core';
import { DialogService } from 'ng-devui';
import { EncodeRulesService } from 'src/app/@core/services/encoderRule/encode-rules.service';
import { UserService } from 'src/app/@core/services/user/user.service';
import { SelectUserComponent } from 'src/app/@shared/components/select-user/select-user.component';
@Component({
  selector: 'app-edit-position',
  templateUrl: './edit-position.component.html',
  styleUrls: ['./edit-position.component.scss']
})
export class EditPositionComponent {
  @Input() data: any;
  options :any;//仓库
  user:any;
  config = {
    maxHeight: '400px',
    width: '400px',
    backdropCloseable: true,
  }//弹窗配置
  msgs: Array<Object> = [];
  positionID: string = '';
  positionNum: string = '';
  Position = {
    warehouseId: null,
    positionName: "",
    isEnabled: true,
    qrCode:"",//二维码
    userID: null
  };//新增仓库
  items:any[]=[
    '启用', '禁用'
  ];
  currentSelectedItem = '启用';
  name: any;
  constructor(private dialogService: DialogService,private UserService:UserService) { }
  ngOnInit(): void {
    this.Position.positionName=this.data.rowItem.positionName
    this.Position.warehouseId = this.data.rowItem.warehouseId
    this.Position.isEnabled = this.data.rowItem.isEnabled
    this.Position.userID = this.data.rowItem.userID
    this.positionID = this.data.rowItem.positionId
    this.positionNum = this.data.rowItem.positionNum
    this.Position.qrCode = this.data.rowItem.qrCode
    if(this.Position.userID){
      this.UserService.GetUserById(this.Position.userID).subscribe((res:any)=>{
        this.name = res.name
      })
    }
    this.currentSelectedItem = this.Position.isEnabled == true ? '启用' : '禁用'
   this.UserService.GetAllEmploy(1,9999).subscribe((res:any)=>{
     this.user = res.items
    })
  }
  valueChange(value: string): void {
    this.Position.isEnabled = value == '启用' ? true : false
  }
  positionData(dialogtype?: string){
    let data = {
      user:this.user,
      display: false,
      placeholder: '请选择人员'
    };
    const results = this.dialogService.open({
      id: 'department',
      ...this.config,
      width: '800px',
      title: '人员',
      data:data,
      content: SelectUserComponent,
      dialogtype: dialogtype,
      onClose: () => {
      },
      buttons: [
        {
          cssClass: 'stress',
          text: '确定',
          handler: ($event: Event) => {
            if(results.modalContentInstance.selectData){
              this.Position.userID = results.modalContentInstance.selectData.id
              this.name = results.modalContentInstance.selectData.name
              results.modalInstance.hide();
            }
            results.modalInstance.hide();
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }//仓位信息
  showToast(type: any,summary:any,content:any) {
    switch (type) {
    default:
      this.msgs = [{ severity: type, summary: summary, content: content }];
    }
  }//提示框
}
